<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="utf-8"/>
    <title>网站后台管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link rel="stylesheet" href="${e.res('/css/bootstrap.min.css')}">
    <link rel="stylesheet" href="${e.res('/css/font-awesome.min.css')}">
    <link rel="stylesheet" href="${e.res('/css/ace.min.css')}">
    <link rel="stylesheet" href="${e.res('/css/jquery.fancybox-1.3.4.css')}">
</head>
<body>
<#include "/pages/moudle/BackHead.ftl">
<div class="main-container" id="main-container">
    <div class="main-container-inner">
    <#include "/pages/moudle/BackSideBar.ftl">
    <@backSideBar chooseTag = '2' />
        <!--页面主体内容-->
        <div class="main-content">
            <!-- 面包屑 -->
            <div class="breadcrumbs" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li>
                        <i class="icon-home home-icon"></i>
                        <a href="/home">首页</a>
                    </li>
                    <li>
                        <a href="<#if type == '2'>/essay/list<#else>/activity/list</#if>"><#if type == '2'>随笔<#else>活动</#if>管理</a>
                    </li>
                    <li class="active"><#if type == '2'>随笔<#else>活动</#if>新增</li>
                </ul>
            </div>
            <!-- 面包屑 -->
            <div class="page-content">
                <div class="page-header">
                    <h1><#if type == '2'>随笔<#else>活动</#if>新增
                        <small>
                            <i class="icon-double-angle-right"></i>
                            上传新的<#if type == '2'>随笔<#else>活动</#if>
                        </small>
                    </h1>
                </div>
                <!-- /.page-header -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->

                        <form class="form-horizontal" role="form">
                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> <#if type == '2'>随笔<#else>活动</#if>标题 </label>

                                <div class="col-sm-9">
                                    <input type="text" id="form-field-1" placeholder="请输入您<#if type == '2'>随笔<#else>活动</#if>的标题"
                                           name="essayTitle" class="col-xs-10 col-sm-5"/>
                                </div>
                            </div>

                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> <#if type == '2'>随笔<#else>活动</#if>描述 </label>

                                <div class="col-sm-9">
                                    <textarea class="form-control limited essayMiao" id="form-field-9" maxlength="200"
                                              style="width:600px;height: 75px;"></textarea>
                                </div>
                            </div>

                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> <#if type == '2'>随笔<#else>活动</#if>内容 </label>

                                <div class="col-sm-9">
                                    <script type="text/javascript" src="${e.res('/js/kindeditor/kindeditor-min.js')}"></script>
                                    <script type="text/javascript" src="${e.res('/js/kindeditor/lang/zh_CN.js')}" ></script>
                                    <script>
                                        var editorFn = {};
                                        var editor1;
                                        KindEditor.ready(function(K) {
                                            editor1 = K.create('textarea[name="essayDesc"]', {
                                                resizeType : 0 ,
                                                width : '650px',
                                                uploadJson : '/fileupload' ,
                                                afterBlur : editorFn.afterBlur,
                                                items : [
                                                    'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'cut', 'copy', 'paste',
                                                    'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
                                                    'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
                                                    'superscript', 'clearhtml', 'quickformat', 'selectall',  '/',
                                                    'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
                                                    'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image','multiimage',
                                                    'table', 'hr', 'emoticons', 'pagebreak',
                                                    'link', 'unlink', '|']
                                            });
                                            editor1.html($("#essayDesc").val());
                                            editor1.readonly(false);
                                        });
                                    </script>
                                    <textarea name="essayDesc" cols="100" rows="8" style="float: left;width: auto; height: 310px; display: none;"></textarea>

                                </div>
                            </div>

                            <div class="space-4"></div>

                            <div class="clearfix form-actions">
                                <div class="center">
                                    <button class="btn btn-info" id="submitButton" type="button">
                                        <i class="icon-ok bigger-110"></i>
                                        保存
                                    </button>

                                    &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;
                                    <a href="<#if type == '2'>/essay/list<#else>/activity/list</#if>" class="btn" type="reset">
                                        <i class="icon-undo bigger-110"></i>
                                        返回
                                    </a>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <!--页面主题内容结束-->
    </div>
</div>
</body>
<script src="${e.res('/js/jquery-1.4.3.min.js')}"></script>
<script src="${e.res('/js/masonry.pkgd.min.js')}"></script>
<script src="${e.res('/js/jquery.lazyload.js')}"></script>
<script src="${e.res('/js/jquery.fancybox-1.3.4.pack.js')}"></script>
<script src="${e.res('/js/jquery.easing-1.3.pack.js')}"></script>
<script src="${e.res('/js/jquery.mousewheel-3.0.4.pack.js')}"></script>
<script src="${e.res('/js/errorHander.js')}"></script>
<script type="text/javascript">

    // 提交事件
    $("#submitButton").click(function () {

        var title = $("input[name='essayTitle']").val();
        var desc = editor1.html();
        var miao = $(".essayMiao").val();
        if(!title){
            alert("标题不能为空");
            return;
        }

        if(!miao){
            alert("描述不能为空");
            return;
        }

        if(!desc){
            alert("内容不能为空");
            return;
        }

        var subParams = {};
        subParams.type = ${type};
        subParams.essayTitle = title;
        subParams.essayMiao = miao;
        subParams.essayDesc = desc;

        $.ajax({
            url: '/addEssay',
            type: 'POST',
            data: subParams,
            success: function (data) {
                if(data.result == "success"){
                    window.location.href = ${type} == '2' ? "/essay/list" : "/activity/list";
                }else{
                    alert(data.result);
                }
            }
        });
    });
</script>
</html>